package Admin;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

public class ManageDTO {

	Connection conn;
	
	public ManageDTO() {
		conn = new MySqlDB().getConn();	
	}

	//회원 정보 검색
	public ArrayList<MemberVo> selectmember(String grade,String find){
		
		String sql = "Select * from member where grade like ? and mid like ?";
		ArrayList<MemberVo> al = new ArrayList<MemberVo>();
		try{
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setString(1, "%"+grade+"%");
			pst.setString(2, "%"+find+"%");
			
			ResultSet rs = pst.executeQuery();
			
			while(rs.next()){
				MemberVo v = new MemberVo();
				v.setMid(rs.getString("mid"));
				v.setIrum(rs.getString("irum"));
				v.setBirth(rs.getString("birth"));
				v.setTel(rs.getString("tel"));
				v.setAddress(rs.getString("address"));
				v.setStamp(rs.getInt("stamp"));
				v.setGrade(rs.getString("grade"));
				
				al.add(v);				
			}
			pst.close();
			rs.close();
			conn.close();
			
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return al;
	}
	
	//디자이너 정보 가져오기
	public DesignerVo checkdesigner(String mid){
		
		DesignerVo v = null;
		String sql = "select * from designer where mid=?";
		try{
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setString(1, mid);
			ResultSet rs = pst.executeQuery();
			
			if(rs.next()){
				v = new DesignerVo();
				v.setMid(mid);
				v.setGrade(rs.getString("grade"));
				v.setWorkday(rs.getString("workday"));
				v.setWorktime(rs.getString("worktime"));
				v.setInfo(rs.getString("info"));
				v.setAttfile(rs.getString("attfile"));
							
			}
			
			
		}catch(Exception e){
			e.printStackTrace();
		}
		return v;
	}

	//회원 정보 수정
	public boolean updatememberdesigner(String mid,int grade,int stamp){
		boolean flag = false;
		String sql = "update member set grade = ? ,stamp= ?  where mid = ?";
		try{
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setInt(1, grade);
			pst.setInt(2, stamp);
			pst.setString(3, mid);
			int t = pst.executeUpdate();
			if(t>0){
				flag = true;
			}
			pst.close();
			conn.close();
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return flag;
	}

	//디자이너 정보 등록
	public boolean registdesigner(DesignerVo v){
		boolean flag = false;
		
		String sql = "insert into designer(mid,workday,worktime,grade,info,attfile) values(?,?,?,?,?,?)";
		try{
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setString(1, v.getMid());
			pst.setString(2, v.getWorkday());
			pst.setString(3, v.getWorktime());
			pst.setString(4, v.getGrade());
			pst.setString(5, v.getInfo());
			pst.setString(6, v.getAttfile());
			
			int f = pst.executeUpdate();
			if(f>0){
				flag = true;
			}			
			pst.close();
			
			
			
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try{
			conn.close();	
			}catch(Exception ex){}
		}
		return flag;
	}

	//관리자 로그인 체크
	public int logincheck(MemberVo v){
		int flag = -1;
		
		String sql = "select pwd,grade from member where mid=?";
		try{
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setString(1, v.getMid());
			
			ResultSet rs = pst.executeQuery();
			
			if(rs.next()){
				String pwd = rs.getString("pwd");
				String grade = rs.getString("grade");
				if(v.getPwd().equals(pwd)){
					if(grade.equals("1")){
					flag = 1;
					}else{
						flag = 4;
					}
				}else{
					flag = 2;
				}				
			}else{
				flag=3;
			}
			pst.close();
			rs.close();
			conn.close();
		
		}catch(Exception e){
			e.printStackTrace();
		}
		return flag;
	}
		
	//회원 가입
	public boolean insertmember(MemberVo v){
		boolean flag = false;
		
		String sql = "insert into member(mid,pwd,address,tel,irum,birth,gosns,gomail,grade,mail,stamp) values(?,?,?,?,?,?,?,?,3,?,0)";
		try{
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setString(1, v.getMid());
			pst.setString(2, v.getPwd());
			pst.setString(3, v.getAddress());
			pst.setString(4, v.getTel());
			pst.setString(5, v.getIrum());
			pst.setString(6, v.getBirth());
			pst.setString(7, v.getGosns());
			pst.setString(8, v.getGomail());
			pst.setString(9, v.getMail());
						
			int f = pst.executeUpdate();
			
			if(f>0){
				flag = true;
			}			
			pst.close();
			
			
			
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try{
			conn.close();	
			}catch(Exception ex){}
		}
		return flag;
	}
	
	//ID중복 검사
	public boolean idck(String mid){
		
		boolean flag = true;
		
		String sql = "select mid from member where mid = ?";
		
		try{
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setString(1, mid);
			
			ResultSet rs = pst.executeQuery();
			
			if(rs.next()){
				flag = false;
			}
			pst.close();
			conn.close();
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return flag;
	}
	
	//디자이너 정보 수정
	public boolean updatedesigner(DesignerVo v){
		boolean flag = false;
		
		String sql = "update designer set workday = ?, worktime = ?,info=?,grade=?,attfile=? where mid = ?";
		try{
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setString(1, v.getWorkday());
			pst.setString(2, v.getWorktime());
			pst.setString(3, v.getInfo());
			pst.setString(4, v.getGrade());
			pst.setString(5, v.getAttfile());
			pst.setString(6, v.getMid());
			
			int r = pst.executeUpdate();
			
			if(r>0){
				flag=true;
			}
			
			pst.close();
			conn.close();
			
			
	
		}catch(Exception e){
			e.printStackTrace();
		}
		return flag;
	}
	
	//디자이너 정보 삭제
	public boolean deletedesigner(String mid){
		boolean flag = false;
		
		String sql = "delete  from designer where mid = ?";
		try{
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setString(1, mid);
			
			int r = pst.executeUpdate();
			if(r>0){
				flag = true;
			}
			
			pst.close();
			conn.close();
	
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return flag;
	}
	
	//헤어스타일 목록 가져오기
	public ArrayList<HairStyleVo> selecthair(String find){
		String sql = "Select * from hair where item like ?";
		ArrayList<HairStyleVo> al = new ArrayList<HairStyleVo>();
		try{
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setString(1, "%"+find+"%");
			
			ResultSet rs = pst.executeQuery();
			
			while(rs.next()){
				HairStyleVo v = new HairStyleVo();
				v.setCode(rs.getInt("code"));
				v.setItem(rs.getString("item"));
				v.setCategory(rs.getString("category"));
				
				al.add(v);
			}
			pst.close();
			rs.close();
			conn.close();
			
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return al;
		
		
		
	}
	
	//헤어 스타일 등록
	public boolean inserthair(HairStyleVo v){
		boolean flag = false;
		
		String sql = "insert into hair(item , category) values(?,?);";
		try{
			PreparedStatement pst = conn.prepareStatement(sql);
			
			pst.setString(1, v.getItem());
			pst.setString(2, v.getCategory());
			
			int f = pst.executeUpdate();
			
			if(f>0){
				flag = true;
			}			
			pst.close();
			
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try{
			conn.close();	
			}catch(Exception ex){}
		}
		return flag;
		
		
	}

	//헤어 스타일 수정
	public boolean updatehair(HairStyleVo v){
		boolean flag = false;
		
		String sql = "update hair set item = ?,category=? where code = ?";
		try{
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setString(1, v.getItem());
			pst.setString(2, v.getCategory());
			pst.setInt(3, v.getCode());
			
			
			int r = pst.executeUpdate();
			
			if(r>0){
				flag=true;
			}
			
			pst.close();
			conn.close();
			
			
	
		}catch(Exception e){
			e.printStackTrace();
		}
		return flag;
	}
	
	//헤어 스타일 삭제
	public boolean deletehair(int code){
		boolean flag = false;
		
		String sql = "delete from hair where code = ?";
		try{
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setInt(1, code);
			
			int r = pst.executeUpdate();
			if(r>0){
				flag = true;
			}
			
			pst.close();
			conn.close();
	
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return flag;
		
	}
	
	//디자이너 별 가격 정보 가져오기
	public ArrayList<PriceVo> price(String mid){
		ArrayList<PriceVo> al = new ArrayList<PriceVo>();
		String sql = "select h.*,p.charge from hair h left outer join price p on h.code=p.code and mid=?";
		try{
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setString(1, mid);
			
			ResultSet rs = pst.executeQuery();
			
			while(rs.next()){
				PriceVo v = new PriceVo();
				v.setMid(mid);
				v.setCode(String.valueOf(rs.getInt("code")));
				v.setItem(rs.getString("item"));
				v.setCharge(String.valueOf(rs.getInt("charge")));
				v.setCategory(rs.getString("category"));
				
				al.add(v);
				
			}
			pst.close();
			rs.close();
			conn.close();
			
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return al;
	}

	//가격 정보 저장/수정 판단
	public boolean chkinup(PriceVo v){
		boolean flag = false;
		boolean result = false;
		
		String sql = "select * from price where mid=? and code=?";
		try{
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setString(1, v.getMid());
			pst.setInt(2, Integer.parseInt(v.getCode()));
			
			
			ResultSet rs = pst.executeQuery();
			
			
			if(rs.next()){
				flag = true;
			}			
			pst.close();
			
			if(flag){
				result = updateprice(v);
			}else{
				result = insertprice(v);
			}
			
			
			
			
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try{
			}catch(Exception ex){}
		}
		return result;
		
	}
	
	//가격 정보 저장
	public boolean insertprice(PriceVo v){
		boolean flag = false;
		
		String sql = "insert into price(mid,code,charge) values(?,?,?)";
		try{
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setString(1, v.getMid());
			pst.setInt(2, Integer.parseInt(v.getCode()));
			pst.setInt(3, Integer.parseInt(v.getCharge()));
			
			
			int f = pst.executeUpdate();
			
			if(f>0){
				flag = true;
			}			
			pst.close();
			
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try{
			}catch(Exception ex){}
		}
		return flag;
		
	}

	//가격 정보 수정
	public boolean updateprice(PriceVo v){
		boolean flag = false;
		
		String sql = "update price set charge=? where mid=? and code=?";
		try{
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setString(2, v.getMid());
			pst.setInt(3, Integer.parseInt(v.getCode()));
			pst.setInt(1, Integer.parseInt(v.getCharge()));
			
			
			int f = pst.executeUpdate();
			
			if(f>0){
				flag = true;
			}			
			pst.close();
			
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try{
			}catch(Exception ex){}
		}
		return flag;
	}

	//커넥션 닫기
	public void closeconn(){
		try{
		conn.close();
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	//예약 정보 가져오기
	public ArrayList<ReservationVo> selectreservation(String category,String find,String[] condition){
		
		ArrayList<ReservationVo> al = new ArrayList<ReservationVo>();
		String sql="";
				
		switch(category){
		case "all" :sql ="select a.irum c_irum, b.*, c.irum d_irum from member a join reservation b on b.mid = a.mid join member c on b.dmid = c.mid where a.mail like ? or c.irum like ? or b.tel like ? or b.days like ? or b.dmid like ? or a.irum like ?";break;
		case "dmid" :sql ="select a.irum c_irum, b.*, c.irum d_irum from member a join reservation b on b.mid = a.mid join member c on b.dmid = c.mid where c.irum like ? or b.dmid like ?";break;
		case "days" : sql = "select a.irum c_irum, b.*,c.irum d_irum from member a join reservation b on b.mid = a.mid join member c on b.dmid = c.mid where days like ?"; break;
		}
				
		
		
		SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd");
		Date nowdate = new Date();
		
		
		
		try{
			PreparedStatement pst = conn.prepareStatement(sql);
			
			switch(category){
			case "all" :  pst.setString(1, "%"+find+"%"); pst.setString(2,"%"+find+"%"); pst.setString(3, "%"+find+"%"); pst.setString(4, "%"+find+"%"); pst.setString(5, "%"+find+"%");pst.setString(6, "%"+find+"%");break;
			case "dmid" :pst.setString(1, "%"+find+"%"); pst.setString(2, "%"+find+"%");break;
			case "days" :  pst.setString(1, "%"+find+"%");break;
			}

			ResultSet rs = pst.executeQuery();
			
			while(rs.next()){
				ReservationVo v = new ReservationVo();
				v.setBno(rs.getInt("bno"));
				v.setAttfile(rs.getString("attfile"));
				v.setC_irum(rs.getString("c_irum"));
				v.setClock(rs.getString("clock"));
				v.setComment(rs.getString("comment"));
				v.setConfirm(rs.getString("confirm"));
				v.setCost(rs.getInt("cost"));
				v.setD_irum(rs.getString("d_irum"));
				v.setDays(rs.getString("days"));
				v.setDmid(rs.getString("dmid"));
				v.setItems(rs.getString("items"));
				v.setMail(rs.getString("mail"));
				v.setMid(rs.getString("mid"));
				v.setRespose(rs.getString("response"));
				v.setTel(rs.getString("tel"));
						
				
				Date compareDate = format.parse(v.getDays());
				
				if(condition[0].equals("all")){
					if(condition[1].equals("all")){
						al.add(v);
					}else if(condition[1].equals("approve")){
						if(v.getConfirm().equals("yes")){
							al.add(v);	
						}
					}else if(condition[1].equals("rejection")){
						if(v.getConfirm().equals("no")){
							al.add(v);	
						}
					}						
				}else if(condition[0].equals("befor")){
					if(nowdate.before(compareDate)){
					if(condition[1].equals("all")){
						al.add(v);
					}else if(condition[1].equals("approve")){
						if(v.getConfirm().equals("yes")){
							al.add(v);	
						}
					}else if(condition[1].equals("rejection")){
						if(v.getConfirm().equals("no")){
							al.add(v);	
						}
					}
					}
				}else if(condition[0].equals("after")){
					if(nowdate.after(compareDate)){
					if(condition[1].equals("all")){
						al.add(v);
					}else if(condition[1].equals("approve")){
						if(v.getConfirm().equals("yes")){
							al.add(v);	
						}
					}else if(condition[1].equals("rejection")){
						if(v.getConfirm().equals("no")){
							al.add(v);	
						}
					}
					}
				}
				
			}
			
			pst.close();
			rs.close();
			conn.close();
			
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return al;
	}

	//한명의 예약정보만 가져오기
	public ReservationVo selectONEreservation(int bno){

		
		
		ReservationVo v = new ReservationVo();
		
		String sql="select a.irum c_irum, b.*,c.irum d_irum from member a join reservation b on b.mid = a.mid join member c on b.dmid = c.mid where bno =?";
		
		
		try{
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setInt(1, bno);
			
			ResultSet rs = pst.executeQuery();
			
			if(rs.next()){
				
				v.setBno(rs.getInt("bno"));
				v.setAttfile(rs.getString("attfile"));
				v.setC_irum(rs.getString("c_irum"));
				v.setClock(rs.getString("clock"));
				v.setComment(rs.getString("comment"));
				v.setConfirm(rs.getString("confirm"));
				v.setCost(rs.getInt("cost"));
				v.setD_irum(rs.getString("d_irum"));
				v.setDays(rs.getString("days"));
				v.setDmid(rs.getString("dmid"));
				v.setItems(rs.getString("items"));
				v.setMail(rs.getString("mail"));
				v.setMid(rs.getString("mid"));
				v.setRespose(rs.getString("response"));
				v.setTel(rs.getString("tel"));
							
			}
			
			pst.close();
			rs.close();
			conn.close();
			
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return v;
		
		
		
	}

	//헤어이름 가져오기
	public ArrayList<String> hairname(String[] item){
		String sql = "Select * from hair";
		
		ArrayList<String> al = new ArrayList<String>();
		try{
			PreparedStatement pst = conn.prepareStatement(sql);
			
			
			ResultSet rs = pst.executeQuery();
			
			while(rs.next()){
				for(int a =0 ; a<item.length ; a++){
					if(item[a].equals(String.valueOf(rs.getInt("code")))){
						al.add(rs.getString("item"));
					}
				}
			}
			pst.close();
			rs.close();
			conn.close();
			
			
			
			
			
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return al;
		
	}

	//예약 승인 하기
	public boolean reservationConfirm(int bno,String temp){
		boolean flag =false;
		
		String sql="update reservation set confirm = ? where bno = ?";		
		
		try{
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setString(1,temp);
			pst.setInt(2, bno);
			
			int a = pst.executeUpdate();
			if(a>0){
				flag = true;
			}
			
			pst.close();
	
			conn.close();
			
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return flag;
		
		
		
	}

	//QnA 목록 받아오기
	public ArrayList<QnAVo> selectQnA(String category,String find,String condition){
		ArrayList<QnAVo> al = new ArrayList<QnAVo>();
		
		String sql = "";
		switch(category){
		case "전체":  sql = "select * from qna where category like ? or subject like ? or mid like ? order by deep";   break;
		case "카테고리": sql = "select * from qna where category like ? order by deep"; break;
		case "제목": sql = "select * from qna where subject like ? order by deep"; break;
		case "작성자": sql = "select * from qna where mid like ? order by deep"; break;
		}		
		
		
		try{			
		
			PreparedStatement pst = conn.prepareStatement(sql);
			
			switch(category){
			case "전체": pst.setString(1, "%"+find+"%"); pst.setString(2, "%"+find+"%"); pst.setString(3, "%"+find+"%"); break;
			case "카테고리": pst.setString(1, "%"+find+"%"); break;
			case "제목": pst.setString(1, "%"+find+"%"); break;
			case "작성자": pst.setString(1, "%"+find+"%"); break;
			}	
			
			
			ResultSet rs = pst.executeQuery();
			
			while(rs.next()){
				QnAVo v = new QnAVo();
				
				v.setMid(rs.getString("mid"));
				v.setMail(rs.getString("mail"));
				v.setConfirm(rs.getString("confirm"));
				v.setContent(rs.getString("content"));
				v.setDeep(rs.getString("deep"));
				v.setGrp(rs.getInt("grp"));
				v.setRno(rs.getInt("rno"));
				v.setSnsreply(rs.getString("snsreply"));
				v.setSubject(rs.getString("subject"));
				v.setTel(rs.getString("tel"));
				v.setWdate(rs.getDate("wdate"));
				v.setCategory(rs.getString("category"));
				
				
				
				
				switch(condition){
				case "all" : al.add(v); break;
				case "complete" : if(rs.getString("confirm").equals("y")){ al.add(v); } break;
				case "incomplete" : if(rs.getString("confirm").equals("n")){ al.add(v); } break;
				}
				
			}
			
			pst.close();
			rs.close();
			conn.close();
					
		
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return al;
	}

	//QnA 하나 불러오기
	public QnAVo selectoneQnA(int rno){
		QnAVo v = new QnAVo();
		
		String sql = "select * from qna where rno = ?";
		try{			
		
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setInt(1, rno);
			ResultSet rs = pst.executeQuery();
			
			
			if(rs.next()){
				
				
				v.setMid(rs.getString("mid"));
				v.setMail(rs.getString("mail"));
				v.setConfirm(rs.getString("confirm"));
				v.setContent(rs.getString("content"));
				v.setDeep(rs.getString("deep"));
				v.setGrp(rs.getInt("grp"));
				v.setRno(rs.getInt("rno"));
				v.setSnsreply(rs.getString("snsreply"));
				v.setSubject(rs.getString("subject"));
				v.setTel(rs.getString("tel"));
				v.setWdate(rs.getDate("wdate"));
				v.setCategory(rs.getString("category"));
							
			}
			
			pst.close();
			rs.close();
			conn.close();
					
		
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return v;
		
		
		
		
		
	}

	//QnA 답변 가져오기
	public ArrayList<QnAVo> selectAnswer(int rno){
	
		ArrayList<QnAVo> al = new ArrayList<QnAVo>();
		
		String sql = "select * from qna where grp ="+rno;
			
		
		try{			
		
			PreparedStatement pst = conn.prepareStatement(sql);
			
					
			ResultSet rs = pst.executeQuery();
			
			while(rs.next()){
				QnAVo v = new QnAVo();
				
				v.setMid(rs.getString("mid"));
				v.setMail(rs.getString("mail"));
				v.setConfirm(rs.getString("confirm"));
				v.setContent(rs.getString("content"));
				v.setDeep(rs.getString("deep"));
				v.setGrp(rs.getInt("grp"));
				v.setRno(rs.getInt("rno"));
				v.setSnsreply(rs.getString("snsreply"));
				v.setSubject(rs.getString("subject"));
				v.setTel(rs.getString("tel"));
				v.setWdate(rs.getDate("wdate"));
				v.setCategory(rs.getString("category"));
				
				if(v.getDeep().split("-").length>1){
					al.add(v);
				}
				
			}
			
			pst.close();
			rs.close();
			conn.close();
					
		
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return al;
	}

	//QnA 답변 저장하기
	public boolean insertAnswer(QnAVo v,int prno){		
		boolean flag = false;
		int rno = endrno();
		
		String sql = "insert into qna(mid,subject,content,mail,category,grp,deep,wdate,snsreply) values(?,?,?,?,?,?,?,now(),'')";
		try{
			
			PreparedStatement pst = conn.prepareStatement(sql);
			
			pst.setString(1, v.getMid());
			pst.setString(2, v.getSubject());
			pst.setString(3, v.getContent());
			pst.setString(4, v.getMail());
			pst.setString(5, v.getCategory());
			pst.setInt(6, prno);
			pst.setString(7, prno+"-"+rno);
		
			
			
			int f = pst.executeUpdate();
			
			if(f>0){
				flag = true;
			}			
			pst.close();
			conn.close();
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try{
			}catch(Exception ex){}
		}
		return flag;
	}

	//QnA deep용 Rno값 구하기
	public int endrno(){
		int rno = 0;
		String sql = "select rno from qna";
		try{
			PreparedStatement pst = conn.prepareStatement(sql);
			ResultSet rs = pst.executeQuery();
			
			while(rs.next()){
				if(rs.getInt("rno")>rno){
					rno = rs.getInt("rno");
				}			
			}
			
			
		}catch(Exception e){
			e.printStackTrace();
		}

		return rno+1;
	}

	//QnA 답변 상태 수정
	public boolean updateconfirm(int prno){
		boolean flag = false;
		
		String sql ="update qna set confirm ='y' where rno ="+prno;
		try{
			PreparedStatement pst = conn.prepareStatement(sql);
			int a = pst.executeUpdate();
			
			if(a>0){
				flag = true;
			}
			pst.close();
			conn.close();
			
			
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return flag;
	}

	//회원 삭제
	public boolean deletemember(String mid){
		boolean flag = false;
		
		String sql = "delete from member where mid = ?";
		try{
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setString(1, mid);
			
			int r = pst.executeUpdate();
			if(r>0){
				flag = true;
			}
			
			pst.close();
			conn.close();
	
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return flag;
		
		
	}

	//예약 삭제
	public boolean deletereservation(int rno){
		boolean flag = false;
		
		String sql = "delete from reservation where bno = ?";
		try{
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setInt(1, rno);
			
			int r = pst.executeUpdate();
			if(r>0){
				flag = true;
			}
			
			pst.close();
			conn.close();
	
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return flag;
	}

}


